﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Bids.Web.IoC;
using Bids.Core.DomainObjects;
using Bids.Service;
using Autofac;
using Autofac.Integration.Mvc;

namespace Bids.Web
{
    // 注意: 有关启用 IIS6 或 IIS7 经典模式的说明，
    // 请访问 http://go.microsoft.com/?LinkId=9394801

    public class Global : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                            "GetImage", // 图片
                            "Img/{*path}",
                            new { controller = "img", action = "get", id = UrlParameter.Optional },
                            null,
                        new string[] { "Bids.Web.Controllers" }
                        );
            routes.MapRoute(
                "Route2", // 任务路由1
                "{controller}/{action}/{id}.html",
                new { controller = "Task", action = "Detail", id = UrlParameter.Optional },
                null,
            new string[] { "Bids.Web.Controllers" }
            );
            routes.MapRoute(
                "Route", 
                "{controller}/{action}.html",
                new { controller = "Task", action = "List", id = UrlParameter.Optional },
                null,
            new string[] { "Bids.Web.Controllers" }
            );
            routes.MapRoute(
                "HomePage", // 主页
                "{action}.html",
                new { controller = "Home", id = UrlParameter.Optional },
                null,
            new string[] { "Bids.Web.Controllers" }
            );

            routes.MapRoute(
                "Default", // 默认路由
                "{controller}/{action}/{id}",
                new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                null,
            new string[] { "Bids.Web.Controllers" }
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            DependencyResolver.SetResolver(UnityControllerFactory.Configure());
            //获取网站设置
            var _iSysSrv = AutofacDependencyResolver.Current.RequestLifetimeScope.Resolve<ISystemService>();
            _iSysSrv.InitConfig();
        }
    }
}